
const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : `0${n}`
}
// 检查是否登录
const check_login = () =>{
  let token = wx.getStorageSync('token');
  return new Promise((resolve,reject) =>{
    wx.checkSession({
      success: (res) => {
        console.log('checkSession 未过期')
        if(token){
          resolve(true)
        }else{
          reject(false)
        }
      },
      fail:() => {
        console.log('checkSession 过期，需要重新登录');
        resolve(false)
      }
    })
  })
}
var myDate = new Date();
//获取当前年
var year = myDate.getFullYear();
//获取当前月
var month = myDate.getMonth() + 1;
//获取当前日
var date = myDate.getDate();
//获取当前日
var date = myDate.getDate();
var h = myDate.getHours();       //获取当前小时数(0-23)
var m = myDate.getMinutes();     //获取当前分钟数(0-59)
var s = myDate.getSeconds();
// 当前时间
function getNow (s) {
  return s < 10 ? '0' + s : s;
}
var nowHM = () => {
  return getNow(h) + ':' + getNow(m) + ':' + getNow(s);
}
var nowYMD = () => {
  return year + '.' + month + '.' + date;
}
module.exports = {
  formatTime,
  check_login,
  nowYMD,
  nowHM
}
